﻿using Anke.SHManage.MSSQLDAL;
using Microsoft.Reporting.WebForms;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Anke.SHManage.Web.Reports
{
    public partial class TJ_DoctorInvoiceUseWebForm : System.Web.UI.Page
    {
        private string reportName;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitPage();
            }
            else
            {
                reportName = Convert.ToString(ViewState["reportName"]);
            }
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            BindReportDataSource();

        }
        private void InitPage()
        {
            this.StartDate.Text = DateTime.Now.AddMonths(-12).ToString("yyyy-MM-dd 07:30:00");
            this.EndDate.Text = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd 07:30:00");
            reportName = Request.QueryString["ReportName"];
            ViewState["reportName"] = reportName;
            BindReportDataSource();
        }
        protected void BindReportDataSource()
        {
            DateTime startTime = Convert.ToDateTime(this.StartDate.Text); //add2022-02-21 plq
            DateTime endTime = Convert.ToDateTime(this.EndDate.Text);
            string start1 = startTime.ToString();
            string end1 = endTime.ToString();
            this.ReportViewer1.LocalReport.DataSources.Clear();

            this.ReportViewer1.LocalReport.ReportPath = Server.MapPath(@"~/Reports/TJ_DoctorInvoiceUseDetail.rdlc");
            Microsoft.Reporting.WebForms.ReportParameter st = new Microsoft.Reporting.WebForms.ReportParameter("startTime", start1);
            Microsoft.Reporting.WebForms.ReportParameter ed = new Microsoft.Reporting.WebForms.ReportParameter("lastTime", end1);
            Microsoft.Reporting.WebForms.ReportParameter pn = new Microsoft.Reporting.WebForms.ReportParameter("personName", reportName);
            this.ReportViewer1.LocalReport.SetParameters(new Microsoft.Reporting.WebForms.ReportParameter[] { st, ed, pn });

            I_InvoiceApprovalDALExt dal4 = new I_InvoiceApprovalDALExt();
            DataTable dt7 = dal4.GetPersonInvoiceUseDetail(startTime, endTime, reportName);
            this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetForUseDetail", dt7));
            DataTable dt8 = dal4.GetPersonInvoiceUseDetailSum(startTime, endTime, reportName);
            this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetForUseDetailSum", dt8));
            this.ReportViewer1.LocalReport.Refresh();
        }
    }
}